package com.shujia.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/*
    1、注册驱动
    2、创建连接对象
    3、创建数据库操作对象
    4、执行sql语句
    5、增删改操作或者查询操作
    6、分析查询结果
    7、关闭连接释放资源
 */
public class HiveJDBC {
    public static void main(String[] args) throws Exception{
        //org.apache.hive.jdbc.HiveDriver
        Class.forName("org.apache.hive.jdbc.HiveDriver");

        Connection conn = DriverManager.getConnection("jdbc:hive2://master:10000/bigdata30");

        PreparedStatement prep = conn.prepareStatement("select * from students where age>? limit 20");

        prep.setInt(1,23);

        ResultSet resultSet = prep.executeQuery();

        while (resultSet.next()){
            int id = resultSet.getInt(1);
            //ctrl+alt + 下键
            String name = resultSet.getString(2);
            int age = resultSet.getInt(3);
            String gender = resultSet.getString(4);
            String clazz = resultSet.getString(5);

            System.out.println("学号："+id+", 姓名："+name+", 年龄："+age+", 性别："+gender+", 班级："+clazz);

        }

        prep.close();
        conn.close();



    }
}
